/*
 * @lc app=leetcode.cn id=812 lang=typescript
 *
 * [812] 最大三角形面积
 */

// @lc code=start

// 三种 for 循环打爆全局
function largestTriangleArea(points: number[][]): number {
    let max = 0;
    for (let i = 0; i < points.length - 2; i++) {
        const a = points[i];
        for (let ii = i + 1; ii < points.length - 1; ii++) {
            const b = points[ii];
            for (let iii = ii + 1; iii < points.length; iii++) {
                const c = points[iii];
                max = Math.max(CalcSum(a, b, c), max);
            }
        }
    }
    return max;
}

const CalcSum = (
    [x1, y1]: number[],
    [x2, y2]: number[],
    [x3, y3]: number[]
) => {
    return (
        Math.abs(x1 * y2 + x2 * y3 + x3 * y1 - x1 * y3 - x2 * y1 - x3 * y2) / 2
    );
};
// @lc code=end
